/*
 * @Author: your name
 * @Date: 2021-05-17 11:18:31
 * @LastEditTime: 2021-05-17 11:34:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \central-system\src\utils\pwdEncrypt.js
 */
import md5 from 'js-md5';
import defaultSettings from '@/config/sys-settings';
import { SM2Encrypt, SM4Encrypt, SM2Decrypt, SM4Decrypt } from './sm4.ts';

export default function pwdEncrypt(value: string) {
	if (value) {
		if (defaultSettings.pwdEncrypType) {
			switch (defaultSettings.pwdEncrypType) {
				// case 'MD5': {
				//   return md5(value);
				// }
				case 'SM4': {
					return SM4Encrypt(value);
				}
				case 'SM2': {
					return SM2Encrypt(value);
				}
				default:
					return '';
			}
		} else {
			return SM4Encrypt(value);
		}
	}
	return '';
}

// 密码解密
export function pwdDecrypt(value: string) {
	if (value) {
		if (defaultSettings.pwdEncrypType) {
			switch (defaultSettings.pwdEncrypType) {
				// case 'MD5': {
				//   return md5(value);
				// }
				case 'SM4': {
					return SM4Decrypt(value);
				}
				case 'SM2': {
					return SM2Decrypt(value);
				}
				default:
					return '';
			}
		} else {
			return SM4Decrypt(value);
		}
	}
	return '';
}
